import os
import shutil
import re


def demo(base_path, copy_dir):
    for root, dir, files in os.walk(base_path):
        for file in files:
            abs_path = os.path.join(root, file)
            with open(abs_path, 'r', encoding='utf-8') as f:
                line = f.read()
                if '"returnResult": "0"' in line or '"returnResult":"0"' in line:
                    # shutil.copy(abs_path, rf'{copy_dir}\{file}')
                    taid = re.findall(':{"taId":"(.*?)"', line)[0]
                    with open(rf'{copy_dir}\history.txt', 'a') as f1:
                        f1.write(taid)
                        f1.write("\n")
                    f1.close()
            f.close()


if __name__ == '__main__':
    base_path = r'D:\Disktop\历史单\History'
    copy_dir = r'D:\Disktop\新建文件夹 (6)'
    demo(base_path, copy_dir)
